﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperWebSocket;

namespace _21WebSocketServer
{
    public class _21Server : WebSocketServer<_21Session>
    {
        //public object SyncObj = new object();

        //public _21Session GetSessionByUserName(string username)
        //{
        //    return GetSessions(m => m.UserName == username).SingleOrDefault() as _21Session;
        //}

        public List<_21Session> GetAllSession()
        {
            return GetSessions(m => true).ToList();
        }

        protected override void OnNewSessionConnected(_21Session session)
        {
            base.OnNewSessionConnected(session);
            lock (Game)
            {
                if(Game.IsStart)
                    session.SendResponseAsync("ERROR 牌局已经开始，请稍后！");
                else
                    Game.SendPlayerInfo(session);
            }
        }

        protected override void OnStartup()
        {
            base.OnStartup();
            Game = new Game();
            Game.Server = this;
        }

        public Game Game { get; set; }
    }
}
